-- [tsx]: Animation.tsx
local ____exports = {} -- 1
local ____Dora = require("Dora") -- 3
local Content = ____Dora.Content -- 3
local Path = ____Dora.Path -- 3
local Sprite = ____Dora.Sprite -- 3
local Vec2 = ____Dora.Vec2 -- 3
local cycle = ____Dora.cycle -- 3
local sleep = ____Dora.sleep -- 3
local thread = ____Dora.thread -- 3
local wait = ____Dora.wait -- 3
____exports.playAnimation = function(node, foldername, interval, loop, reverse, size) -- 6
	node:removeAllChildren() -- 7
	local names = Content:getAllFiles(foldername) -- 8
	if not names or #names == 0 then -- 8
		print(("Warning: No files found in folder \"" .. foldername) .. "\"") -- 11
		return -- 12
	end -- 12
	local frames = {} -- 16
	for ____, name in ipairs(names) do -- 17
		local frame = Sprite(Path(foldername, name)) or Sprite() -- 18
		frame.visible = false -- 19
		if size then -- 19
			frame.size = size -- 20
		end -- 20
		if reverse then -- 20
			frame.width = -frame.width -- 22
		end -- 22
		frame:addTo(node) -- 24
		frames[#frames + 1] = frame -- 25
	end -- 25
	if #frames == 1 then -- 25
		frames[1].visible = true -- 28
	else -- 28
		local i = 0 -- 30
		frames[i + 1].visible = true -- 31
		node:loop(function() -- 32
			sleep(interval) -- 33
			frames[(i + 1) % #names + 1].visible = true -- 34
			frames[i + 1].visible = false -- 35
			i = (i + 1) % #names -- 36
			return not loop -- 37
		end) -- 32
	end -- 32
end -- 6
____exports.NodeMove = function(node, speed, pos, loop) -- 48
	if #pos < 1 then -- 48
		print("nodemove: 至少需要一个位置点") -- 51
		return nil -- 52
	end -- 52
	local pathSegments = {} -- 56
	if #pos == 1 then -- 56
		pathSegments[#pathSegments + 1] = {start = pos[1], ["end"] = pos[1], distance = 0, time = 0} -- 60
	else -- 60
		do -- 60
			local i = 0 -- 67
			while i < #pos - 1 do -- 67
				local start = pos[i + 1] -- 68
				local ____end = pos[i + 1 + 1] -- 69
				local dx = ____end.x - start.x -- 72
				local dy = ____end.y - start.y -- 73
				local distance = math.sqrt(dx * dx + dy * dy) -- 74
				local time = distance / (speed * 10) -- 79
				pathSegments[#pathSegments + 1] = {start = start, ["end"] = ____end, distance = distance, time = time} -- 81
				i = i + 1 -- 67
			end -- 67
		end -- 67
		if loop then -- 67
			local start = pos[#pos] -- 86
			local ____end = pos[1] -- 87
			local dx = ____end.x - start.x -- 90
			local dy = ____end.y - start.y -- 91
			local distance = math.sqrt(dx * dx + dy * dy) -- 92
			local time = distance / (speed * 10) -- 95
			pathSegments[#pathSegments + 1] = {start = start, ["end"] = ____end, distance = distance, time = time} -- 97
		end -- 97
	end -- 97
	node.position = pos[1] -- 102
	return thread(function() -- 105
		local currentNode = 0 -- 106
		while true do -- 106
			if not loop and currentNode >= #pathSegments then -- 106
				break -- 111
			end -- 111
			currentNode = currentNode % #pathSegments -- 113
			local segment = pathSegments[currentNode + 1] -- 115
			local finished = false -- 118
			cycle( -- 122
				segment.time, -- 122
				function(time) -- 122
					local currentPos = Vec2(segment.start.x + (segment["end"].x - segment.start.x) * time, segment.start.y + (segment["end"].y - segment.start.y) * time) -- 124
					node.position = currentPos -- 130
					if time == 1 then -- 130
						finished = true -- 132
					end -- 132
				end -- 122
			) -- 122
			wait(function() -- 136
				return finished -- 137
			end) -- 136
			currentNode = currentNode + 1 -- 141
		end -- 141
	end) -- 105
end -- 48
return ____exports -- 48